<template>
	<view>


		<view class="header" @click="goBack">
			<view class="arrow">
			</view>
			<view class="title">
				分类
			</view>
		</view>



		<view class="VerticalBox">
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation :scroll-top="verticalNavTop" style="height:calc(100vh)">
				<view class="cu-item" :class="index == tabCur ? 'text-green cur' : ''" v-for="(item, index) in list" :key="index"
				 @tap="TabSelect" :data-id="index">
					{{ item.name }}
				</view>
			</scroll-view>
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation style="height:calc(100vh)" :scroll-into-view="'main-' + mainCur"
			 @scroll="VerticalMain">
				<view class="padding-top padding-lr" v-for="(item, index) in list" :key="index" :id="'main-' + index">
					<!-- <block v-for="(item1, id) in item.goods" :key="id"> -->
						<view class="cu-bar solid-bottom bg-white">
							<view class="action">
								<text class="cuIcon-title text-green"></text>
								{{ item.name }}
							</view>
						</view>
						<block v-for="(item1, id) in item.goods" :key="id">
						<view class="cu-list menu-avatar" @click="inputNum(item1)">
							<view class="cu-item">
								<!-- style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg);" -->
								<view class="cu-avatar round lg" style="width: 100rpx; height: 100rpx;border-radius: 50rpx;">
									<image :src="item1.image" mode=""></image>
								</view>
								<view class="content flex-direction">
									<text>{{item1.name}}</text>
									<!-- <view class="">
										<text>库存: </text>
										<view class="cu-tag round bg-gradual-orange sm">{{item.num}}</view>
									</view> -->
								</view>
						
							</view>
						</view>
					</block>
				</view>
			</scroll-view>
		</view>



		<u-popup v-model="show" mode="center" width="500rpx" height="160px" border-radius="20">
			<view class="show" style="height: 60rpx; line-height: 60rpx; padding-top: 20rpx;">
				喜之郎果冻
			</view>
			<view class="show-poup flex-box">
				<text>数量</text>
				<input type="text" v-model="num" placeholder="请输入" />
			</view>
			<!-- <view class="show-poup flex-box">
				<text>备注</text>
				<input type="text" v-model="memo" placeholder="请输入" />
			</view> -->
			<view class="flex-around add-clas">
				<view class="" style="background-color: #CCCCCC;" @click="show = false">
					取消
				</view>
				<view class="bg-gradual-blue" @click="addInpput">
					确定
				</view>
			</view>
		</u-popup>







	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				load: true,
				show: false,
				memo: '',
				num: '',
				stockId: '',
				goodsList: [],
				inofId: '',
				itemName: '',

			};
		},
		onReady() {
			uni.hideLoading();
		},
		onLoad(e) {
			this.stockId = e.stock
			this.getList()
		},
		methods: {

			addInpput() {
				console.log('111111111', this.stockId)
				console.log('输入的数量', this.num)
				// console.log('memo', this.memo)
				console.log('this.inofId', this.inofId)
				
				if(this.num == '') return this.$tools.msg('输入的数量不能为空')
				this.show = false
				var obj = {}
				// obj.memo = this.memo
				obj.num = this.num
				obj.goods_id = this.inofId
				obj.name = this.itemName.name
				obj.image = this.itemName.image
				obj.unit = this.itemName.unit
				this.goodsList.push(obj)
				
				console.log("itemName ", this.itemName)
				console.log("goodsList ", this.goodsList) 
			},


			inputNum(item) {
				this.memo = ''
				this.num = ''
				this.show = true
				this.inofId = item.id
				this.itemName = item
				console.log(item)
			},


			goBack(id) {
				console.log(id)
				uni.navigateBack({
					url: '/pages/putStock/addShop?navigatorProp=' + 4
				})

				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				// prevPage.$vm.godList = JSON.stringify(this.goodsList);
				prevPage.$vm.listFrom = this.goodsList  //修改上一页data里面的searchVal参数值为1211
				prevPage.$vm.godList = this.goodsList 
				console.log('this.goodsList',this.goodsList)

			},

			// 获取;列表
			async getList() {
				const res = await this.$u.post("api/jinxiao.Goods/index", {});
				this.list = res.data
				console.log('获取;列表', this.list)
			},





			TabSelect(e) {
				this.tabCur = e.currentTarget.dataset.id;
				this.mainCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50;
			},
			VerticalMain(e) {
				// #ifdef MP-ALIPAY
				return false; //支付宝小程序暂时不支持双向联动
				// #endif
				let that = this;
				let tabHeight = 0;
				if (this.load) {
					for (let i = 0; i < this.list.length; i++) {
						let view = uni.createSelectorQuery().select('#main-' + this.list[i].id);
						view.fields({
								size: true,
							},
							data => {
								this.list[i].top = tabHeight;
								// tabHeight = tabHeight + data.height;
								// this.list[i].bottom = tabHeight;
							},
						).exec();
					}
					this.load = false;
				}
				let scrollTop = e.detail.scrollTop + 10;
				for (let i = 0; i < this.list.length; i++) {
					if (scrollTop > this.list[i].top && scrollTop < this.list[i].bottom) {
						this.verticalNavTop = (this.list[i].id - 1) * 50;
						this.tabCur = this.list[i].id;
						console.log(scrollTop);
						return false;
					}
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.header {
		width: 100%;
		height: 150rpx;
		line-height: 150rpx;
		display: flex;
		align-items: center;
		// padding-left: 10rpx;
		padding-top: 30rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #000000;
		background: #EEEEEE;

		.arrow {
			position: relative;
			display: inline-block;
		}

		.arrow::before {
			content: '';
			width: 10px;
			height: 10px;
			border: 0px;
			border-bottom: solid 2px #fff;
			border-left: solid 2px #fff;
			-ms-transform: rotate(45deg);
			-webkit-transform: rotate(45deg);
			transform: rotate(45deg);
			position: absolute;
			top: 50%;
			left: 0;
			margin-top: -4px;
			margin-left: 28rpx;
		}

		.title {
			color: #fff;
			margin: 0 auto;
		}
	}





	.fixed {
		position: fixed;
		z-index: 99;
	}

	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
	}

	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;
		background-color: #fff;
		margin: 0;
		border: none;
		height: 50px;
		position: relative;
	}

	.VerticalNav.nav .cu-item.cur {
		background-color: #f1f1f1;
	}

	.VerticalNav.nav .cu-item.cur::after {
		content: '';
		width: 8upx;
		height: 30upx;
		border-radius: 10upx 0 0 10upx;
		position: absolute;
		background-color: currentColor;
		top: 0;
		right: 0upx;
		bottom: 0;
		margin: auto;
	}

	.VerticalBox {
		display: flex;
	}

	image {
		width: 100%;
		height: 100%;
		border-radius: 50rpx;
	}

	.VerticalMain {
		background-color: #f1f1f1;
		flex: 1;
	}


	.show-poup {
		width: 80%;
		height: 70rpx;
		line-height: 70rpx;
		border-radius: 10rpx;
		margin: 36rpx auto;
		padding-left: 30rpx;
		background-color: #F5F5F5;
	}

	.add-clas {
		width: 100%;
		height: 60rpx;

		view {
			width: 30%;
			height: 60rpx;
			color: #FFFFFF;
			line-height: 60rpx;
			border-radius: 30rpx;
			text-align: center;
		}
	}
</style>
